var ip = require('ip')
var os = require('os')
// get all local ips
exports.getAllLocalIp = function (name) {
  var interfaces = os.networkInterfaces()
  var all = Object.keys(interfaces).map(function (nic) {
    var addresses = interfaces[nic].filter(function (details) {
      details.family = details.family.toLowerCase()
      if (details.family !== 'ipv4' || ip.isLoopback(details.address)) {
        return false
      } else if (!name) {
        return true
      }
      return name === 'public' ? ip.isPrivate(details.address)
        : ip.isPublic(details.address)
    })
    return addresses.length ? addresses[0].address : undefined
  }).filter(Boolean)
  return all.length ? all
    : []
}
